import json

# 原始JSON数据
with open('./train.json', 'r', encoding='utf-8') as file:
    data = json.load(file)



# 将原始JSON数据解析为Python字典
# original_data = json.loads(original_json)


# 转换逻辑
def convert_json(data):
    # 初始化新的对话列表
    new_conversations = []

    # 遍历原始对话列表
    for conv in data['conversations']:
        new_conversations.append({'role': 'user', 'content': conv['role']})
        new_conversations.append({'role': 'assistant', 'content': conv['content']})

        # 创建新的JSON结构并返回
    new_data = {'conversations': new_conversations}
    return new_data

# 调用转换函数并打印结果
new_json_data = convert_json(data)
print('=========>')
print(json.dumps(new_json_data,ensure_ascii=False, indent=2))
# print(json.dumps(new_json_data, indent=2, ensure_ascii=False))
